package com.ycz.springcloud.config;/*
 @author ycz
 @date 2021-07-25-17:02  
*/

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登录拦截器
 */
public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler
    ) throws Exception {

        String loginName= (String) request.getSession().getAttribute("loginName");
        System.out.println("拦截的"+loginName);
        System.out.println("拦截了");

        if (loginName==null){
            request.setAttribute("msg","没有权限，请先登录");
            request.getRequestDispatcher("/index").forward(request,response);
            return false;
        }else {
            return true;
        }


    }
}
